package com.zgm.ch06.aop.xml.introduce._3_4;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zgm.ch06.aop.aspectJ.introduce._2_7.interfaces.CallTracker;
import com.zgm.ch06.aop.services.StockService;
import com.zgm.ch06.aop.services.UserService;

public class XmlDemo {

	public static void main(String[] args) {
		ApplicationContext ac = new ClassPathXmlApplicationContext("com/zgm/ch06/aop/xml/introduce/_3_4/_3_4-context.xml");
		
		UserService userService = (UserService) ac.getBean("userService");
		StockService stockService = (StockService) ac.getBean("stockService");
		
		userService.login("zgm");
		stockService.getStockLevel("S");   //报NullPointerException
		stockService.applyDiscounts(new Date(), BigDecimal.ONE);
		
		describeTracker(userService);
		describeTracker(stockService);
		
	}
	
	private static void describeTracker(Object o) {
		CallTracker t = (CallTracker) o;
		System.out.println(t.describe());
	}
}
